<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_yxw/model')->方法名();
*/
namespace jy_yxw;
defined('BY_JYA') or exit('error');
class worker extends \plugin{
	public function member_show($mid,$default_url='',$default=false){		
		$member=pdo_get('jy_yxw_worker',array('id'=>intval($mid)),array('id','title','mobile','logo'));
		if(!$member){
			$member=$default?:array('nickname'=>'无');
		}else{
			$member['url']=$default_url?str_replace('{mid}',$member['id'],$default_url):'';
			$member['nickname']=$member['title']?:'无';
			$member['avatar']=tomedia($member['logo']);
		}
		return $member;
	}
	public function getmyworkers($juese,$storeid=0){
		$worker=pdo_get('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_SESSION['workerid']));
		$workerids=$worker['workerids'];
		$workerids=json_decode($workerids,true);
		$workers=array();
		foreach($workerids as $wv){
			$njuese=pdo_getcolumn('jy_yxw_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$wv['id']),'juese');
			if($njuese==$juese){
				$workers[$wv['id']]=$wv;
			}
		}
		if($worker['juese']==$juese){
			$workers[$worker['id']]=$worker;
		}else{
			$jueses=$worker['jueses'];
			if(strpos($jueses,';'.$juese.';')!==false){
				$workers[$worker['id']]=$worker;
			}
			if(strpos($jueses,';1;')!==false || $_SESSION['juese_id']==1 || $_SESSION['juese_id']==2 || $_SESSION['juese_id']==15){
				$all=pdo_getall('jy_yxw_worker',array('juese'=>$juese,'uniacid'=>$_SESSION['uniacid'],'storeid'=>$storeid?:$_SESSION['storeid']));
				foreach($all as $wv2){
					$workers[$wv2['id']]=$wv2;
				}
			}
		}
		return $workers;
	}
	public function getworkers($juese,$storeid=0){
		$params=array('juese OR'=>'juese='.$juese.' or jueses like \'%;'.$juese.';%\'','status'=>1,'uniacid'=>$_SESSION['uniacid']);
		if($storeid){
			$params['storeid']=$storeid;
		}
		$workers=pdo_getall('jy_yxw_worker',$params,array('id','title'),'id');
		return $workers;
	}
}
?>